package Float;

import java.math.BigDecimal;
import java.math.BigInteger;

public class Float {
    public static void main(String[] args) {
        //float必须在小数后面添加f/F
        float a=6.28f;
        double b=6.28;
        System.out.println(a==b);//false

        //浮点型是不精确的,不能用于比较
        float c=232423423f;
        double d=c+1;
        if(c==d){
            System.out.println("c==d");
        }else {
            System.out.println("c!=d");
        }

        //java.math包下面有两个类BigInteger和BigDecimal
        //BigInteger实现任意精度的整数运算
        //BigDecimal实现任意精度的浮点运算

        System.out.println("############");

        BigDecimal bd=BigDecimal.valueOf(1.0);
        bd=bd.subtract(BigDecimal.valueOf(0.1));
        bd=bd.subtract(BigDecimal.valueOf(0.1));
        bd=bd.subtract(BigDecimal.valueOf(0.1));
        bd=bd.subtract(BigDecimal.valueOf(0.1));
        bd=bd.subtract(BigDecimal.valueOf(0.1));
        System.out.println(bd);//结果是0.5,我们想要的值
        System.out.println(1.0-0.1-0.1-0.1-0.1-0.1);

        BigDecimal bd2=BigDecimal.valueOf(0.1);
        BigDecimal bd3=BigDecimal.valueOf(1.0/10);
        System.out.println(bd2.equals(bd3));//比较bd2与bd3是否相等
    }
}
